import utils from "../../utils/index";
import {
  fansModel,commonModel
} from "../../apis/index"
const app = getApp()
import regeneratorRuntime from '../../libs/wxPromise.min';
Page({
  data: {
    placeholder:'输入名星名字',
    name:'', //粉丝团名称
    avatar:'', //粉丝团头像
    fid:'', // 粉丝团ID
  },
  mixins: [require('../../myMixin.js')],
  async onLoad(options) {
    let {fid=''} = options
    console.log(fid)
    if(!fid){
      utils.showToast('未获取粉丝团','none')
      return
    }
    this.data.fid = fid
    let {name='',avatar=''} = await fansModel.fansClubQuery({fid})
    this.setData({
      name:name,
      avatar:avatar
    })
  },
  onShow: function () {
  },
  fansClubCreate(){
    let { name, avatar, fid } = this.data
    if(name&&avatar&&fid){
      utils.showLoading()
      fansModel.fansClubUpdate({name,avatar,fid}).then(res=>{
        utils.showModalContent('','粉丝团编辑成功！', '确定',  false,'').then(res=>{
          if(res){
            utils.navigateBack({
              delta:1
            })
          }
          utils.hideAll()
        })
      })
    }else{
      utils.showToast('请添加粉丝团信息','none')
    }
  },
  onInputChange(e){
    let {value} = e.detail
    this.data.name = value.trim()
  },
  chooseImage(){
    let _this= this
    utils.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album','camera'],
      success: (result)=>{
        let filePath = result.tempFilePaths[0]
        commonModel.uploadFile({filePath}).then(res=>{
          _this.setData({
            avatar:res
          })
        })
      }
    })
  }

})